import 'package:flutter/material.dart';
import 'package:flutter_eve_plugin/components/health/radar_chart.dart';
import 'package:flutter_eve_plugin/components/health/title_view.dart';
import 'package:flutter_eve_plugin/pages/health/actions.dart';
import 'package:flutter_eve_plugin/route/main.dart';
import 'package:flutter_eve_plugin/store/main.dart';
import 'package:flutter_eve_plugin/store_vm/app_vm.dart';
import 'package:flutter_eve_plugin/store_vm/health/main.dart';
import 'package:flutter_eve_plugin/utils/screen_util.dart';
import 'package:flutter_redux/flutter_redux.dart';

class SysStateWidget extends StatefulWidget {
  const SysStateWidget({
    Key key,
    @required this.dataList,
    this.userColor,
  }) : super(key: key);

  final List<RadarViewModel> dataList;
  final Color userColor;

  @override
  _SysStateWidgetState createState() => _SysStateWidgetState();
}

class _SysStateWidgetState extends State<SysStateWidget> {
  @override
  Widget build(BuildContext context) {
    return StoreConnector<AppState, AppStateViewModel>(converter: (store) {
      return AppStateViewModel(
          state: store.state,
          healthStateViewModel:
          HealthStateViewModel(homeDescClick: (pushName, index) {
            store.dispatch(healthSysCurrPage(store, index));
            Navigator.pushNamed(context, pushName);
          }));
    }, builder: (context, vm) {
      return SliverToBoxAdapter(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            SizedBox(
              height: setRatio(30),
            ),
            HealthTitleViewWidget(
              title: '各系统健康状况',
            ),
            Stack(
              overflow: Overflow.visible,
              children: <Widget>[
                Positioned(
                  child: Center(
                      child: Container(
                        height: setRatio(300),
                        width: setRatio(300),
                        child: CustomPaint(
                          painter: RadarView(
                              radius: setRatio(100),
                              dataList: widget.dataList,
                              userColor: widget.userColor),
                        ),
                      )),
                ),
                ///通过绘制设置的点击事件无效， 退一步处理
                Positioned(
                  left: setRatio(150),
                  top: setRatio(10),
                  child: GestureDetector(
                    onTap: () => vm.healthStateViewModel
                        .homeDescClick(RouteConstant.SysStateMainPage, 1),
                    child: Container(
                      width: setRatio(75),
                      height: setRatio(30),
                      color: Colors.transparent,
                    ),
                  ),
                ),
                Positioned(
                  left: setRatio(280),
                  top: setRatio(110),
                  child: GestureDetector(
                    onTap: () => vm.healthStateViewModel
                        .homeDescClick(RouteConstant.SysStateMainPage, 3),
                    child: Container(
                      color: Colors.transparent,
                      width: setRatio(75),
                      height: setRatio(30),
                    ),
                  ),
                ),
                Positioned(
                  left: setRatio(242),
                  top: setRatio(238),
                  child: GestureDetector(
                    onTap: () => vm.healthStateViewModel
                        .homeDescClick(RouteConstant.SysStateMainPage, 4),
                    child: Container(
                      color: Colors.transparent,
                      width: setRatio(75),
                      height: setRatio(30),
                    ),
                  ),
                ),
                Positioned(
                  left: setRatio(60),
                  top: setRatio(238),
                  child: GestureDetector(
                    onTap: () => vm.healthStateViewModel
                        .homeDescClick(RouteConstant.SysStateMainPage, 0),
                    child: Container(
                      color: Colors.transparent,
                      width: setRatio(75),
                      height: setRatio(30),
                    ),
                  ),
                ),
                Positioned(
                  left: setRatio(15),
                  top: setRatio(110),
                  child: GestureDetector(
                    onTap: () => vm.healthStateViewModel
                        .homeDescClick(RouteConstant.SysStateMainPage, 2),
                    child: Container(
                      color: Colors.transparent,
                      width: setRatio(75),
                      height: setRatio(30),
                    ),
                  ),
                )
              ],
            ),
            Container(
              width: setRatio(375),
              height: setRatio(7),
              color: Color(0xFFF5F5F5),
            ),
            SizedBox(
              height: setRatio(29),
            ),
            HealthTitleViewWidget(
              title: '系统说明',
            ),
            SizedBox(
              height: setRatio(24),
            ),
          ],
        ),
      );
    });
  }
}
